package com.z.system.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.z.system.utils.R;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 测试日志AOP的控制器
 */
@RestController
@RequestMapping("/api/test/log")
@Tag(name = "日志测试", description = "日志AOP功能测试接口")
public class TestLogController {

    /**
     * 测试正常请求的日志记录
     */
    @GetMapping("/normal")
    @Operation(summary = "正常请求测试", description = "测试正常请求的日志记录功能",
               responses = @io.swagger.v3.oas.annotations.responses.ApiResponse(
                   responseCode = "200", description = "成功响应"))
    public ResponseEntity<?> testNormal(@Parameter(description = "测试参数", required = true) @RequestParam String param) {
        return ResponseEntity.ok(R.success("测试成功", param));
    }

    /**
     * 测试异常请求的日志记录
     */
    @GetMapping("/error")
    @Operation(summary = "异常请求测试", description = "测试异常请求的日志记录功能",
               responses = @io.swagger.v3.oas.annotations.responses.ApiResponse(
                   responseCode = "500", description = "服务器错误"))
    public ResponseEntity<?> testError() {
        throw new RuntimeException("测试异常情况");
    }

    /**
     * 测试POST请求的日志记录
     */
    @PostMapping("/post")
    @Operation(summary = "POST请求测试", description = "测试POST请求的日志记录功能",
               responses = @io.swagger.v3.oas.annotations.responses.ApiResponse(
                   responseCode = "200", description = "成功响应"))
    public ResponseEntity<?> testPost(@Parameter(description = "请求体参数", required = true, schema = @Schema(implementation = TestRequest.class)) @RequestBody TestRequest request) {
        return ResponseEntity.ok(R.success("POST测试成功", request));
    }

    /**
     * 测试请求参数对象
     */
    public static class TestRequest {
        private String name;
        private Integer age;
        private String description;

        // Getters and Setters
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
    }
}